﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {

    public class ContainerOrderFocusTraversalPolicy implements FocusTraversalPolicy {

        public function getComponentAfter(_arg1:Component):Component{
            return (this.getComponentAfterImp(_arg1, true));
        }
        protected function getComponentAfterImp(_arg1:Component, _arg2:Boolean=true):Component{
            var _local6:Component;
            var _local7:Component;
            if (_arg1 == null){
                return (null);
            };
            if ((((_arg1 is Container)) && (_arg2))){
                _local6 = this.getFirstComponent((_arg1 as Container));
                if (_local6 != null){
                    return (_local6);
                };
            };
            var _local3:Container = _arg1.getParent();
            if (_local3 == null){
                return (this.getFirstComponent((_arg1 as Container)));
            };
            var _local4:int = _local3.getIndex(_arg1);
            var _local5:int = _local3.getComponentCount();
            if (_local4 >= 0){
                while (++_local4 < _local5) {
                    _local7 = this.getFocusableComponent(_local3.getComponent(_local4));
                    if (_local7 != null){
                        return (_local7);
                    };
                };
            };
            return (this.getComponentAfterImp(_local3, false));
        }
        public function getComponentBefore(_arg1:Component):Component{
            return (this.getComponentBeforeImp(_arg1));
        }
        protected function getComponentBeforeImp(_arg1:Component):Component{
            var _local4:Component;
            if (_arg1 == null){
                return (null);
            };
            var _local2:Container = _arg1.getParent();
            if (_local2 == null){
                return (this.getLastComponent((_arg1 as Container)));
            };
            var _local3:int = _local2.getIndex(_arg1);
            while (--_local3 >= 0) {
                _local4 = this.getLastComponent(_local2.getComponent(_local3));
                if (_local4 != null){
                    return (_local4);
                };
            };
            if (this.accept(_local2)){
                return (_local2);
            };
            return (this.getComponentBeforeImp(_local2));
        }
        public function getDefaultComponent(_arg1:Container):Component{
            return (this.getFirstComponent(_arg1));
        }
        protected function getFirstComponent(_arg1:Container):Component{
            var _local4:Component;
            if (_arg1 == null){
                return (null);
            };
            var _local2 = -1;
            var _local3:int = _arg1.getComponentCount();
            while (++_local2 < _local3) {
                _local4 = this.getFocusableComponent(_arg1.getComponent(_local2));
                if (_local4 != null){
                    return (_local4);
                };
            };
            return (null);
        }
        protected function getLastComponent(_arg1:Component):Component{
            var _local4:Component;
            var _local5:Component;
            var _local2:Container = (_arg1 as Container);
            if (_local2 == null){
                if (this.accept(_arg1)){
                    return (_arg1);
                };
                return (null);
            };
            var _local3:int = _local2.getComponentCount();
            while (--_local3 >= 0) {
                _local4 = _local2.getComponent(_local3);
                if (this.isLeaf(_local4)){
                    if (this.accept(_local4)){
                        return (_local4);
                    };
                };
                _local5 = this.getLastComponent((_local4 as Container));
                if (_local5 != null){
                    return (_local5);
                };
            };
            if (this.accept(_local2)){
                return (_local2);
            };
            return (null);
        }
        private function isLeaf(_arg1:Component):Boolean{
            var _local2:Container;
            if ((_arg1 is Container)){
                _local2 = (_arg1 as Container);
                return ((_local2.getComponentCount() == 0));
            };
            return (true);
        }
        private function accept(_arg1:Component):Boolean{
            return (((((((!((_arg1 == null))) && (_arg1.isShowing()))) && (_arg1.isFocusable()))) && (_arg1.isEnabled())));
        }
        private function getFocusableComponent(_arg1:Component):Component{
            var _local2:Container;
            var _local3:Component;
            if (((_arg1.isShowing()) && (_arg1.isEnabled()))){
                if (_arg1.isFocusable()){
                    return (_arg1);
                };
                if ((_arg1 is Container)){
                    _local2 = (_arg1 as Container);
                    _local3 = _local2.getFocusTraversalPolicy().getDefaultComponent(_local2);
                    if (_local3 != null){
                        return (_local3);
                    };
                };
            };
            return (null);
        }

    }
}//package org.aswing 
